{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "mature-chile",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/reverse-words-in-a-string\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of C++ online submissions for Reverse Words in a String.\n",
    "Memory Usage: 8.1 MB, less than 40.85% of C++ online submissions for Reverse Words in a String.\n",
    "\n",
    "\n",
    "```cpp\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <string>\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    string reverseWords(string s) {\n",
    "        //8:50\n",
    "        auto l = split_it(s);\n",
    "        reverse(l.begin(), l.end());\n",
    "        string new_s = \"\";\n",
    "        for (auto word: l) {\n",
    "            new_s += \" \" + word;\n",
    "        }\n",
    "        new_s.erase(0,1);\n",
    "        return new_s;\n",
    "        //9:00\n",
    "    }\n",
    "    vector<string> split_it(string s) {\n",
    "        vector<string> l;\n",
    "        bool start = false;\n",
    "        for (auto c : s) {\n",
    "            if ((start == false) && (c !=' ')) {\n",
    "                string new_s = \"\";\n",
    "                new_s.push_back(c);\n",
    "                l.push_back(new_s);\n",
    "                start = true;\n",
    "            } else if ((start == true) && (c == ' ')) {\n",
    "                start = false;\n",
    "            } else if ((start == true) && (c != ' ')) {\n",
    "                l[l.size()-1].push_back(c); \n",
    "            }\n",
    "        }\n",
    "        return l;\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "impressive-excess",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
